// Linux header
#include <sys/socket.h>
#include <linux/if_ether.h>
#include <netinet/in.h>
// lib header
#include "glog/logging.h"
// user defined header
#include "packet.h"

#define PACKET_MAX 1024
int get_packet()
{
    int sock;
    if((sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP))) < 0){
        perror(strerror(errno));
        fprintf(stderr, "create socket error.\n");
        exit(0);
    }

    char packet[PACKET_MAX];
    while(1){
        int rd = recvfrom(sock, packet, PACKET_MAX, 0, NULL, NULL);
        if(rd < 46){
            printf("Incomplete packet (errno is %d)\n",  errno);
            close(sock);
            exit(0);
        }
        printf("%s", packet);
    }
    close(sock);


    return 0;
}